import axios from 'axios'
import { Modal } from 'antd'
const baseURL = 'https://www.easy-mock.com/mock/5c237574853e57374ca24342/api'
export default class Axios {
  static ajax(options) {
    let loadingDom = document.getElementById('ajaxLoading')
    return new Promise((resolve, reject) => {
      if (!options.hideLoading) {
        loadingDom.style.display = 'block'
      }
      axios({
        url: options.url,
        method: options.method ? options.method : 'get',
        baseURL,
        timeout: 5000,
        params: (options.data && options.data.params) || ''
      }).then(res => {
        if (!options.hideLoading) {
          loadingDom.style.display = 'none'
        }
        if (res.status === 200) {
          resolve(res.data.data)
        } else {
          Modal.info({
            title: '错误',
            content: res.data.msg
          })
          reject(res.data)
        }
      })
    })
  }
}
